﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Navigation;
using WPF_DbCenter.GlobalDefine;
using System.Data.OleDb;
using WPF_DbCenter.CommonMethod;
using WPF_DbCenter.SqlCE.DbEnginer;
using WPF_DbCenter.AdditionUI;

namespace WPF_DbCenter
{
    /// <summary>
    /// Interaction logic for Main.xaml
    /// </summary>
    public partial class Main : Page
    {
        public Main()
        {
            InitializeComponent();

            InitSelf();

            InitSkin();
        }

        private void InitSkin()
        {
            ComboBoxItem bo = new ComboBoxItem();
            bo.Content = "Orange";
            bo.Tag = new Uri(@"Skins/Orange.xaml", UriKind.Relative);
            cmbSkin.Items.Add(bo);

            ComboBoxItem bo2 = new ComboBoxItem();
            bo2.Content = "White";
            bo2.Tag = new Uri(@"Skins/White.xaml", UriKind.Relative);
            cmbSkin.Items.Add(bo2);


            cmbSkin.SelectionChanged += new SelectionChangedEventHandler(cmbSkin_SelectionChanged);
        }

        void cmbSkin_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cmbSkin.SelectedItem == null)
            {
                return;
            }

            ResourceDictionary rd = null ;

            ComboBoxItem item = cmbSkin.SelectedItem as ComboBoxItem;
            Uri uri = item.Tag as Uri;
            if (uri != null)
            {
                rd = Application.LoadComponent(uri) as ResourceDictionary;
                Application.Current.Resources = rd;
            }

            
        }


        private void InitSelf()
        {
            this.cmbDbType.Items.Clear();
            
            var p = from pp in GlobalDefine.MyDefine.CurDbCollection
                    orderby pp.SortIndex ascending
                    select pp;


            foreach (GlobalDefine.DbTypeCollection item in p)
            {
                this.cmbDbType.Items.Add(item);
            }
            if (this.cmbDbType.Items.Count > 0)
            {
                this.cmbDbType.SelectedIndex = 1;
            }

            //NativeGate.Util util = new NativeGate.Util();
            //if (!util.LicenseKeySimplestValidation(Properties.Settings.Default.SQLCELicense))
            //{
            //    MessageBox.Show("Invalid Key, System will Exit");
            //    Application.Current.Shutdown();
            //}
        }


        private void DoNextButton_Click(object sender, RoutedEventArgs e)
        {
            DbTypeCollection curSelect = this.cmbDbType.SelectedItem as DbTypeCollection;
            if (curSelect != null)
            {
                MyDefine.CurSelectedCollectin = curSelect;
                if (MyDefine.CurSelectedCollectin.MainUI_URI == null)
                {
                    MessageBox.Show("Not Support Currently");
                    return;
                }
                NavigationService ns = NavigationService.GetNavigationService(this);

                ns.Navigate(new Uri(MyDefine.CurSelectedCollectin.MainUI_URI, UriKind.Relative));
            }

            //DbTypeCollection curSelect = this.cmbDbType.SelectedItem as DbTypeCollection;
            //CoreEA.CoreE.UsedDatabaseType dbType = CoreEA.CoreE.UsedDatabaseType.SqlServer;
            //if (curSelect != null)
            //{
            //    switch (curSelect.MyType)
            //    {
            //        case SupportedDbType.SqlServer:
            //            dbType = CoreEA.CoreE.UsedDatabaseType.SqlServer;
            //            break;
            //        case SupportedDbType.MySql:
            //            dbType = CoreEA.CoreE.UsedDatabaseType.MySql;
            //            break;
            //        case SupportedDbType.OleDb:
            //            dbType = CoreEA.CoreE.UsedDatabaseType.OleDb;
            //            break;
            //        case SupportedDbType.SqlCe:
            //            dbType = CoreEA.CoreE.UsedDatabaseType.SqlCE35;
            //            break;
            //        default:
            //            throw new Exception("Not implemented type");
            //    }

            //    Utility.Utility ut = new WPF_DbCenter.Utility.Utility(dbType);
            //    this.NavigationService.Navigate(ut);

        }

    }
}
